package com.ww.learn.oop

class MachineOperator private constructor(val name: String) {

    fun checkin() = checkedIn++

    fun checkout() = checkedIn--

    companion object MachineOperatorFactory {
        var checkedIn = 0
        fun minimumBreak() = "15 minutes every 2 hours"

        fun create(name: String): MachineOperator {
            val instance = MachineOperator(name)
            instance.checkin()
            return instance
        }
    }
}

fun main() {
//    MachineOperator("Mater").checkin()
    println(MachineOperator.minimumBreak())
    println(MachineOperator.checkedIn)

    // 访问同伴
//    val ref = MachineOperator.MachineOperatorFactory

    val operator = MachineOperator.create("Mater")
    println(MachineOperator.checkedIn)
}